Completed
Push — master ( e02f9a...716024 )
by Maxence
04:32
created

api.retrieveOptions   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 14
rs 9.4285
cc 1
nc 1
nop 2

2 Functions

Rating   Name   Duplication   Size   Complexity  
A 0 4 1
A 0 4 1
1
/*
2
 * FullTextSearch - Full text search framework for Nextcloud
3
 *
4
 * This file is licensed under the Affero General Public License version 3 or
5
 * later. See the COPYING file.
6
 *
7
 * @author Maxence Lange <[email protected]>
8
 * @copyright 2018
9
 * @license GNU AGPL version 3 or any later version
10
 *
11
 * This program is free software: you can redistribute it and/or modify
12
 * it under the terms of the GNU Affero General Public License as
13
 * published by the Free Software Foundation, either version 3 of the
14
 * License, or (at your option) any later version.
15
 *
16
 * This program is distributed in the hope that it will be useful,
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19
 * GNU Affero General Public License for more details.
20
 *
21
 * You should have received a copy of the GNU Affero General Public License
22
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
23
 *
24
 */
25
26
27
/** global: OC */
28
/** global: settings */
29
/** global: result */
30
/** global: search */
31
/** global: nav */
32
33
34
var api = {
35
36
37
	search: function (request, callback) {
38
		var res = {status: -1};
39
40
		$.ajax({
41
			method: 'GET',
42
			url: OC.generateUrl('/apps/fulltextsearch/v1/search'),
43
			data: {
44
				request: JSON.stringify(request)
45
			}
46
		}).done(function (res) {
47
			result.displayResult(res);
48
			nav.onResultDisplayed(res);
49
			api.onCallback(callback, res);
50
		}).fail(function () {
51
			nav.failedToAjax();
52
			api.onCallback(callback, res);
53
		});
54
	},
55
56
57
	retrieveOptions: function (providerId, callback) {
58
		var res = {status: -1};
59
60
		$.ajax({
61
			method: 'GET',
62
			url: OC.generateUrl('/apps/fulltextsearch/options/' + providerId)
63
		}).done(function (res) {
64
			searchbox.onOptionsLoaded(res);
0 ignored issues
show
Bug introduced by
The variable searchbox seems to be never declared. If this is a global, consider adding a /** global: searchbox */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
65
			api.onCallback(callback, res);
66
		}).fail(function () {
67
			nav.failedToAjax();
68
			api.onCallback(callback, res);
69
		});
70
	},
71
72
73
	onCallback: function (callback, result) {
74
		if (callback && (typeof callback === 'function')) {
75
			if (typeof result === 'object') {
76
				callback(result);
77
			} else {
78
				callback({status: -1});
79
			}
80
		}
81
	}
82
83
};
84